<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="100px">
            <el-form-item label="拼团名称" prop="collageName">
              <el-input v-model="queryParams.collageName" placeholder="请输入拼团名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="拼团编号" prop="collageCode">
              <el-input v-model="queryParams.collageCode" placeholder="请输入拼团编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="支付状态" prop="payStatus">
              <el-select v-model="queryParams.payStatus" placeholder="请选择支付状态" clearable>
                <el-option v-for="dict in pay_status" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <el-table border v-loading="loading" :data="collageCompensationLogList">
        <el-table-column label="拼团封面" align="center">
          <template #default="scope">
            <image-preview :src="scope.row.collageImage" :width="100" :height="100"/>
          </template>
        </el-table-column>
        <el-table-column label="拼团名称" align="center" prop="collageName" />
        <el-table-column label="拼团编号" align="center" prop="collageCode" />
        <el-table-column label="拼团总金额" align="center" prop="totalMoney" />
        <el-table-column label="拼团销售金额" align="center" prop="saleMoney" />
        <el-table-column label="拼团手续费" align="center" prop="serviceMoney" />
        <el-table-column label="已缴纳手续费" align="center" prop="yetPayServiceMoney" />
        <el-table-column label="剩余需补差手续费" align="center">
          <template #default="scope">
            <span style="color: red; font-weight: bold">{{scope.row.compensationMoney}}</span>
          </template>
        </el-table-column>
        <el-table-column label="支付状态" align="center">
          <template #default="scope">
            <dict-tag :options="pay_status" :value="scope.row.payStatus" />
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
  </div>
</template>

<script setup name="CollageCompensationLog" lang="ts">
import { listCollageCompensationLog, getCollageCompensationLog, delCollageCompensationLog, addCollageCompensationLog, updateCollageCompensationLog } from '@/api/system/collageCompensationLog';
import { CollageCompensationLogVO, CollageCompensationLogQuery, CollageCompensationLogForm } from '@/api/system/collageCompensationLog/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { pay_status } = toRefs<any>(proxy?.useDict('pay_status'));

const collageCompensationLogList = ref<CollageCompensationLogVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const collageCompensationLogFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: CollageCompensationLogForm = {
  id: undefined,
  collageId: undefined,
  shopId: undefined,
  collageAccountLogId: undefined,
  collageName: undefined,
  collageCode: undefined,
  collageImage: undefined,
  totalMoney: undefined,
  saleMoney: undefined,
  serviceMoney: undefined,
  realityServiceMoney: undefined,
  yetPayServiceMoney: undefined,
  compensationMoney: undefined,
  payStatus: undefined,
}
const data = reactive<PageData<CollageCompensationLogForm, CollageCompensationLogQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    collageId: undefined,
    shopId: undefined,
    collageAccountLogId: undefined,
    collageName: undefined,
    collageCode: undefined,
    collageImage: undefined,
    totalMoney: undefined,
    saleMoney: undefined,
    serviceMoney: undefined,
    realityServiceMoney: undefined,
    yetPayServiceMoney: undefined,
    compensationMoney: undefined,
    payStatus: undefined,
    params: {
    }
  },
  rules: {}
});

const { queryParams, form, rules } = toRefs(data);

/** 查询拼团补差记录列表 */
const getList = async () => {
  loading.value = true;
  const res = await listCollageCompensationLog(queryParams.value);
  collageCompensationLogList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}

/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  collageCompensationLogFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}

onMounted(() => {
  getList();
});
</script>
